import 'package:enterprise_v6_app/app/core/constans/dict_data_info.dart';
import 'package:enterprise_v6_app/app/core/utils/module_permissions_util.dart';
import 'package:enterprise_v6_app/app/core/values/images.dart';
import 'package:enterprise_v6_app/app/data/entities/application/securtity_base_drawer.dart';
import 'package:enterprise_v6_app/app/modules/application/special_operation/special_home_page/special_home_view.dart';
import 'package:enterprise_v6_app/app/modules/application/special_operation/special_list/special_list_view.dart';
import 'package:enterprise_v6_app/app/modules/application/special_operation/standing_book_page/standing_book_view.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class SpecialPageController extends GetxController {
  /// 筛选右侧栏控制Key
  final popRightScaffoldKey = GlobalKey<ScaffoldState>();

  /// 展开收起控制key
  final scaffoldKey = GlobalKey<ScaffoldState>();

  /// 选中的页面
  int selectIndex = 0;

  /// 右侧筛选样式
  Widget? filterWidget;

  // 标题列表
  final titleList = [
    SecurityBaseEntity(
      title: '总览',
      icon: AppImages.icon_eduction_list,
      expandTitle: '总览',
      currentPageTitle: 0,
      pages: [SpecialHomePage()],
      path: '/home',
    ),
    SecurityBaseEntity(
      title: '作业列表',
      icon: AppImages.icon_work_list,
      expandTitle: '作业列表',
      currentPageTitle: 0,
      pages: [SpecialListWidget()],
      path: '/specialList',
    ),
    SecurityBaseEntity(
      title: '台账',
      icon: AppImages.icon_work_ledger,
      expandTitle: '台账',
      currentPageTitle: 0,
      pages: [StandingBookPage()],
      path: '/standingBook',
    ),
  ];

  @override
  void onInit() {
    super.onInit();
    initModule();
  }

  /// 根据后台权限初始化菜单
  void initModule() {
    ModulePermissionsUtil.removeRoleMenu(titleList: titleList, routes: AppRoutes.specialOperation);
    update();
  }

  /// 点击左侧菜单
  /// [index] 索引
  void selectLeftMenu(int index) {
    selectIndex = index;
    update();
  }

  /// title选择切换
  /// [titleIndex] 标题索引
  /// [index] 页面索引
  void selectTitle(int titleIndex, int index) {
    titleList[titleIndex].currentPageTitle = index;
    update();
  }

  /// 点击展开菜单
  /// [index] 索引
  void selectExpandMenu(int index) {
    selectIndex = index;
    Get.back();
    update();
  }

  @override
  void onReady() {
    super.onReady();

    /// 获取字典数据
    DictDataInfo.getTreeDictionaryDataByWorkType();
  }
}
